package com.briup.srms.base.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.srms.base.bean.DictData;
import com.briup.srms.base.service.IDictDataService;
import com.jacky.base.utils.Message;
import com.jacky.base.utils.MessageUtil;
import com.jacky.base.utils.PageVM;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @program: 杰普基础管理系统
 * @description: 数据字典控制器类
 * @author: charles
 * @create: 2020-12-27 17:22
 **/
@Api(description = "数据字典相关接口")
@Validated
@RestController
@RequestMapping("/dict")
public class DictDataController {

    @Autowired
    private IDictDataService dictDataService;

    @ApiOperation(value = "分页多条件获取数据字典信息")
    @GetMapping("pageQuery")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"),})
    public Message pageQuery(int page, int pageSize) {
        PageVM<DictData> pageVM = dictDataService.pageQuery(page, pageSize);
        return MessageUtil.success(pageVM);
    }

    @ApiOperation(value = "通过id删除")
    @ApiImplicitParams(@ApiImplicitParam(name = "id", value = "主键", paramType = "query", required = true))
    @GetMapping("deleteById")
    public Message deleteById(long id) {
        dictDataService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新消息信息", notes = "如果参数中包含id后端认为是更新操作，如果参数中不包含id认为是插入操作")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(DictData dictData) {
        dictDataService.saveOrUpdate(dictData);
        return MessageUtil.success("更新成功");
    }

}
